package com.dd.ent.car.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dd.ent.car.R;


/**
 * Created by dengqu on 2016/8/8.
 */
public class ShowMoreTextView extends LinearLayout implements View.OnClickListener {
    private TextView tvBefore;
    private TextView tvAfter;
    private TextView hidden;
    private TextView show;

    public ShowMoreTextView(Context context) {
        super(context);
        init(context);
    }

    public ShowMoreTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.show_more_textview, this);
        tvBefore = (TextView) findViewById(R.id.tv_before);
        tvAfter = (TextView) findViewById(R.id.tv_after);
        hidden = (TextView) findViewById(R.id.tv_hidden);
        show = (TextView) findViewById(R.id.tv_showmore);

        hidden.setOnClickListener(this);
        show.setOnClickListener(this);
    }

    public void setText(String text) {
        tvBefore.setText(text);
    }

    public void reset() {
        tvBefore.setVisibility(VISIBLE);
        tvAfter.setVisibility(GONE);
        hidden.setVisibility(GONE);
        show.setVisibility(VISIBLE);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_showmore:
                tvBefore.setVisibility(GONE);
                tvAfter.setVisibility(VISIBLE);
                tvAfter.setText(tvBefore.getText());
                hidden.setVisibility(VISIBLE);
                show.setVisibility(GONE);
                break;

            case R.id.tv_hidden:
                tvBefore.setVisibility(VISIBLE);
                tvAfter.setVisibility(GONE);
                tvBefore.setText(tvAfter.getText());
                hidden.setVisibility(GONE);
                show.setVisibility(VISIBLE);
                break;
        }
    }
}
